//
//  netApI.m
//  photoLibrayIos8
//
//  Created by jing zhao on 5/23/16.
//  Copyright © 2016 jing zhao. All rights reserved.
//

#import "NetApI.h"

@interface NetApI() <NSURLConnectionDelegate>

@end

@implementation NetApI

+(void)postApiNetWithApi:(NSString *)url
               andParams:(NSDictionary*)params
               andSucces:(void (^)(NSObject* object))sucess
              andFailure:(void (^)(NSObject* object))failure{

    NSURL * urlSend = [NSURL URLWithBaseString:url parameters:params];
    NSURLSessionDataTask *session = [[NSURLSession sharedSession]dataTaskWithURL:urlSend completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        NSError *errorJson = nil;
        if (!error && !errorJson){
            NSObject *object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&errorJson];
            sucess(object);
        }
        else
            failure(error.description);
    }];
    
    [session resume];
}

@end
